﻿using System;
using System.Linq.Expressions;
using UtfprLibrary.Exceptions;

namespace UtfprLibrary.Helpers {
    public static class PropertyHelper {
        /// <summary>
        /// TODO
        /// </summary>
        /// <exception cref="UtfprLibrary.Exceptions.UtfprHelpersException">Thrown when an exception occurs.</exception>
        public static string GetName<T>(Expression<Func<T, object>> expr) {
            try {
                return ((expr.Body as UnaryExpression).Operand as MemberExpression).Member.Name;
            } catch (Exception ex) {
                throw new UtfprHelpersException(Properties.Resources.Helpers_PropertyHelper_ExMsg_GetName, ex);
            }
        }
    }
}